<template>
  <div class="login-setting">
    <div class="login-setting">
      <el-form
        ref="userForm"
        :model="userInfo"
        :rules="rules"
        label-width="120px"
        style="margin-left: 120px; margin-top: 30px"
      >
        <el-form-item label="姓名:" prop="username">
          <el-input v-model="userInfo.username" style="width:300px" />
        </el-form-item>

        <el-form-item label="密码:" prop="password">
          <el-input v-model="userInfo.password" type="password" style="width:300px" />
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="saveUserInfoFn">更新</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { getUserDetailById } from '@/api/user'
import { saveUserDetailById } from '@/api/employees'
export default {
  name: 'LoginSetting',
  data() {
    return {
      userInfo: {
        username: '',
        password: ''
      },
      rules: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' }
        ],
        password: [

          { required: true, message: '请输入密码', trigger: 'blur' }
        ]

      }
    }
  },
  created() {
  //  调用获取员工基本信息
    this.getUserDetailByIdFn()
  },
  methods: {
    // 获取员工基本信息
    async getUserDetailByIdFn() {
      // 用路由的query方式来获取url中的路径id值进行传参
      const res = await getUserDetailById(this.$route.query.id)
      // console.log(res)
      this.userInfo = res.data
    },

    //
    saveUserInfoFn() {
      this.$refs.userForm.validate(async valid => {
        if (!valid) return
        const res = await saveUserDetailById(this.userInfo)
        console.log(res)
        this.$message.success(res.message)
      })
    }
  }

}
</script>

<style lang="scss" scoped></style>
